package com.lx.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lx.beans.Goods;
import com.lx.service.impl.GoodsService;
import com.lx.utils.FRUtil;

@Controller
@RequestMapping("/goods")
public class GoodsController {

	@Autowired
	private GoodsService gService;
	
	/**
	 * 及时生成，刷新页面就生成，跳转到ftl
	 * @param map
	 * @return
	 */
	@RequestMapping("/list")
	public String list(Map<String,Object> map){
		List<Goods> gList = gService.findGoods();
		map.put("gList", gList);
		return "glist";
	}
	
	/**
	 * 点击按钮生成html，跳转到html
	 * @param session
	 * @return
	 */
	@RequestMapping("/refresh")
	public String refresh(HttpSession session){
		List<Goods> gList = gService.findGoods();
		Map<String,Object> model = new HashMap<>();
		model.put("gList", gList);
		//当然，这里也可以使用FRUtil.createPageManual
		FRUtil.createPageByWebRoot("glist.ftl", model, "glist.html");
		return "redirect:/html/glist.html";
	}
}
